<template>
  <el-row type="flex" justify="center">
    <el-col :span="8">
      <el-form ref="formDateRef" label-position="top" label-width="80px" :model="messageData" :rules="messageRules">
        <el-form-item label="旧密码" prop="password">
          <el-input v-model="messageData.password" show-password type="password" style="min-width: 200px;" />
        </el-form-item>
        <el-form-item label="新密码" prop="newPassword">
          <el-input v-model="messageData.newPassword" show-password type="password" style="min-width: 200px;" />
        </el-form-item>
        <el-form-item label="再次输入密码" prop="rePasswrod">
          <el-input v-model="messageData.rePasswrod" show-password type="password" style="min-width: 200px;" />
        </el-form-item>
        <el-form-item style="display: flex;justify-content:center">
          <el-button type="primary" plain @click="submitPas">确认修改</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
import { getUserInfo } from '@/api/user'

export default {
  data() {
    return {
      userData: [],
      messageData: {
        id: '',
        password: '',
        newPassword: '',
        rePasswrod: ''
      },
      messageRules: {
        password: [
          {
            required: true, message: '请输入密码', trigger: 'blur'
          }
        ],
        newPassword: [
          {
            required: true, message: '请输入密码', trigger: 'blur'
          }
        ],
        rePasswrod: [
          {
            required: true, message: '请输入密码', trigger: 'blur'
          }
        ]
      }
    }
  },

  mounted() {
    this.getUserInfo()
  },
  methods: {
    async getUserInfo() {
      const res = await getUserInfo()
      // this.messageData.password = res.password
      console.log(res)
      console.log(this.messageData)
    },
    submitPas() {
      this.$confirm('是否修改密码?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$refs.formDateRef.validate(async isok => {
          if (isok) {
            console.log(this.messageData)
            this.$message({
              type: 'success',
              message: '修改成功!'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消修改'
        })
      })
    }

  }
}
</script>

<style>

</style>
